package generator;

import java.io.File;
import java.io.PrintStream;

import java.io.IOException;

import writer.CSVWriter;

public class PermutationGenerator {
	
	private static CSVWriter output;
	private static int count;
	private static int fileCount;

	
	public static void PermutationGenerator() throws IOException{
		count=-3;
	
		fileCount=1;
		output= new CSVWriter(new File("src/generator/Combo1.txt"));
	
	}
	
	private static void incCount() throws IOException{
	//	System.out.println("Count is"+count);
		count++;
		if(count==1029){
			fileCount++;
			output= new CSVWriter(new File("src/generator/Comobo"+fileCount+".txt"));
			count=0;
		}
	}
	
	
	
	
	private static void getCombos() throws IOException{
		int[] next= new int[4];
		next[0]=1;
		next[1]=2;
		next[2]=3;
		next[3]=4;

		for (int i=1;i<=1029;i++){
			next[0]=i;
			
		//	combos.add(next.clone());
			printToFile(printCombo(next.clone()));
			incCount();
			for(int j=2;j<=1029;j++){
				next[1]=j;
		//		System.out.println("["+next[0]+","+next[1]+","+next[2]+","+next[3]+"]");
		//		combos.add(next.clone());
				printToFile(printCombo(next.clone()));
				incCount();
				for(int k=3;k<=1029;k++){
					next[2]=k;
		//			System.out.println("["+next[0]+","+next[1]+","+next[2]+","+next[3]+"]");
		//			combos.add(next.clone());
					printToFile(printCombo(next.clone()));
					incCount();
					for(int l=4;l<=1029;l++){
						next[3]=l;
		//				System.out.println("["+next[0]+","+next[1]+","+next[2]+","+next[3]+"]");
		//				combos.add(next.clone());
						printToFile(printCombo(next.clone()));
						incCount();
					}
				}
			}
		}
		
		
	}
		
		
	
	
	public static void main(String[] args0 ) throws IOException{
		PermutationGenerator();
		getCombos();
	
	}
	
	




	
	public static void printToFile(StringBuffer line) throws IOException{
		System.out.println(line.toString());
		output.write(line.toString());
		
	}
	
	private static StringBuffer printCombo(int[] x) throws IOException{
	//	System.out.println("["+x[0]+","+x[1]+","+x[2]+","+x[3]+"]");
		Quartet q= new Quartet(x);
		return new StringBuffer(x[0]+" "+x[1]+" "+x[2]+" "+x[3]+","+q.divergence);
//		return (x[0]+" "+x[1]+" "+x[2]+" "+x[3]+","+q.divergence);
		}

}
